//
//  ReplenishmentTCell.swift
//  Pods
//
//  Created by eme on 2017/4/20.
//
//

import UIKit
import Kingfisher
import RxSwift
import RickonCore
import BrandonCore

class ReplenishmentTCell: UITableViewCell {
    //商品名称
    @IBOutlet weak var pdname_Lb: UILabel!
    //店铺进货价
    @IBOutlet weak var shprice_Lb: UILabel!
    
    @IBOutlet weak var jinPriceImg_V: UIImageView!
    //品牌名称
    @IBOutlet weak var brname_Lb: UILabel!
    //起定量
    @IBOutlet weak var mod_Lb: UILabel!
    @IBOutlet weak var addCart_Btn: UIButton!
    
    @IBOutlet weak var seperateLine_V: UIView!
    //  利润
    @IBOutlet weak var profit_V: UIView!
    @IBOutlet weak var profit_Lb: UILabel!
    @IBOutlet weak var sellout_ImgV: UIImageView!
    @IBOutlet weak var img1_ImgV: UIImageView!
    
    private let disposeBag = DisposeBag()
    
    var addCart_Closure:((Void)->Void)?
    var item :HpProductModel?{
        didSet{
            if let item = self.item {
                if item.stock == 0 || item.pdstate != "3" {
                    self.sellout_ImgV.isHidden = false
                    self.sellout_ImgV.image = UIImage(named: item.stock == 0 ?"sellout":"failure", in: RobbCore.bundle, compatibleWith: nil)
                }else{
                    self.sellout_ImgV.isHidden = true
                }
                if item.istimeby == "1" {
                    self.addCart_Btn.isEnabled = false
                    self.pdname_Lb.setReplaceText(text: "\(AppConfig.timelimit)\(item.pdname)", replace: AppConfig.timelimit)
                }else {
                    self.addCart_Btn.isEnabled = item.stock > 0 && item.pdstate == "3"
                    self.pdname_Lb.text = item.pdname
                }
                self.brname_Lb.text = item.brname
                self.img1_ImgV.setUrlImage(item.img1)
                self.profit_Lb.text = item.profit.getFormatStr()
                self.jinPriceImg_V.image = UIImage(named: AppData.getPriceImgName(), in: RobbCore.bundle, compatibleWith: nil)
                self.shprice_Lb.text = AppData.getFinalShowPrice(jinPrice: item.shprice, lingPrice: item.bdprice).getPriceStr()
                
            }
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.seperateLine_V.backgroundColor = Theme.v.separate_Line
        self.profit_V.changeBorderColor(UIColor(hex: "f7c029"),cornerRadius: 1)
        self.addCart_Btn.rx.tap.subscribe(onNext:{ _ in
            if let addCart_Closure = self.addCart_Closure{
                addCart_Closure()
            }
        }).addDisposableTo(disposeBag)
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
